<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="../../../common/common-jstl.jspf" %>
<%@ include file="../../../common/common-js.jspf" %>
<!DOCTYPE html>
<html>
<head>
    <base href="${pageContext.request.contextPath }/"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
        .container {
            width: 100%;
            height: 300px;
        }

        .title {
            width: 100%;
            height: 12%;
            background-color: #5E5E5E;
        }

        .title > span {
            color: white;
            font-size: 16px;
            font-family: "黑体";
            line-height: 32px;
            text-indent: 1em;
            display: block;
        }

        .content {
            width: 100%;
            height: 88%;
            background-color: #F5F5F5;
        }

        .content table {
            border-collapse: collapse;
            width: 100%;
        }

        .content table td, .content table th {
            border: 1px solid #ccc;
            padding: 10px;
            text-align: center;
        }

    </style>
</head>
<body>
<div class="container">
    <div class="title"><span>学生信息列表</span></div>
    <div class="content">
        <table>
            <tr>
                <th>编号</th>
                <th>名称</th>
                <th>账号</th>
                <th>密码</th>
                <th>角色</th>
                <th>班级</th>
                <th>操作<a href="javascript:add()">[添加]</a></th>
            </tr>
            <c:forEach items="${stuList }" var="stu">
                <tr>
                    <td>${stu.stuId }</td>
                    <td>${stu.stuName }</td>
                    <td>${stu.account }</td>
                    <td>${stu.password }</td>
                    <td>${stu.role.roleName }</td>
                    <td>${stu.stuClass }</td>
                    <td>
                        <a href="judgeDelete('${stu.stuId }')">删除 </a>
                        |
                        <a href="javascript:updatePanel('${stu.stuId }','${stu.role.roleId }')">修改 </a>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </div>
</div>
<script type="text/javascript">
    //添加的函数
    function add() {
        layer.open({
            type: 2,
            title: false,
            shadeClose: false,
            shade: 0.5,
            skin: 'layui-layer-rim',
            area: ['1100px', '400px'],
            content: "studentInfoController?flag=initAdd"
        })
    }
    //删除的函数
    function judgeDelete(stuId) {
        var url = "studentInfoController";
        $.get(url, {flag: "delete", stuId: stuId}, function (data) {
            if (data == "ok") {
                layer.msg("删除成功", {
                    icon: 1,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    layer.open({
                        type: 2,
                        title: false,
                        shadeClose: false,
                        shade: 0.5,
                        skin: 'layui-layer-rim',
                        /* closeBtn:false, */
                        area: ['1100px', '400px'],
                        content: "studentInfoController?flag=list"
                    });
                });
            } else {
                layer.msg("删除失败");
            }
        });

    }
    //修改的函数
    function updatePanel(stuId, roleId) {
        layer.open({
            type: 2,
            title: false,
            shadeClose: false,
            shade: 0.5,
            skin: 'layui-layer-rim',
            area: ['1100px', '400px'],
            content: "studentInfoController?flag=initUpdate&stuId=" + stuId + "&roleId=" + roleId
        })
    }

</script>
</body>
</html>